
import config from "../config/config";
import {dbLogger} from "../logger";



import {Sequelize} from "sequelize-typescript";
import path from "path";
import Redis from "ioredis";
import RedisWrapper from "../redis/RedisWrapper";


export const sequelize = new Sequelize(config.db.database, config.db.user, config.db.password, {
    host: config.db.host,
    // 选择一种支持的数据库:
    // 'mysql', 'mariadb', 'postgres', 'mssql', 'sqlite', 'snowflake', 'db2' or 'ibmi'
    dialect: 'mysql',
    logging:msg=> dbLogger.info(msg),
    models: [path.join(__dirname, '..','model/**/*.{ts,js}')],
    define:{
        freezeTableName:true,
    },
    pool:{
        max:10,
        min:0,
        idle:10000,
        acquire: 30000,
    }
});
const redis = new RedisWrapper({
    host: 'localhost',
    port: 6379,
    password: 'Abc123456'
});
global.redis = redis;
(async () => {
    try {
        await sequelize.authenticate();

        console.log('Connection has been established successfully.');
    } catch (error) {
        console.error('Unable to connect to the database:', error);
    }
})()
